<?php
/*
 * Session variables:
 * $_SESSION['type'] [string] = user type of the logged in user
 * $_SESSION['authorised'] [boolean] = whether or not the current user is logged in
 * $_SESSION['tcname'] [string] = the name of the tutorial centre
 * $_SESSION['signupmessage'] [string] = message notifying the user about the sign up
 */
session_start();
if(isset($_SESSION['authorised']) && $_SESSION['authorised'] == true)
{
	if(isset($_SESSION['type']))
	{
		if($_SESSION['type'] == 'administrator')
		{
			$email = $_SESSION['account_name'];
			$acctype = $_SESSION['account_type'];
			$firstname=$_SESSION['create_firstname'];
			$password= $_SESSION['password'];
			$tutorial_centre=$_SESSION['tcname'];
			
			$message="Hi $firstname!\r\n\r\n";
			$message.="Welcome to Tutorial Business Management System! \r\n";
			$message.="\r\n\r\nYour are now registered in $tutorial_centre as $acctype\r\n";
			$message.="\r\nYour username is $email.\r\n";
			$message.="Your password is $password.";
			$message.="\r\n\r\nThanks, \r\n\r\n";
			$message.="TBMS team \r\n";
								
			require_once('class.phpgmailer.php');
			$mail = new PHPGMailer();
			$mail->Username = 'cs192tbms@gmail.com'; 
			$mail->Password = 'notnamed';
			$mail->From = 'cs192tbms@gmail.com'; 
			$mail->FromName = 'CS 192 TBMS Group';
			$mail->Subject = 'Welcome to Tutorial Business Management System';
			$mail->AddAddress("$email");
			$mail->Body = "$message";
			$mail->Send();
			
			unset($_SESSION['account_name'],$_SESSION['account_type'],$_SESSION['create_firstname'],$_SESSION['password']);
			header('Location:admin_manageaccounts.php');
			exit();
		}
		elseif($_SESSION['type'] == 'student')
		{
			header('Location: student_index.php');
			exit();
		}
		elseif($_SESSION['type'] == 'tutor')
		{
			header('Location: tutor_index.php');
			exit();
		}
		elseif($_SESSION['type'] == 'parent')
		{
			header('Location: parent_index.php');
			exit();
		}
  }
}
else
{
    header('Location: index.php');
}
?>
